package com.yz.jdd.webview.net;

import com.google.gson.JsonObject;
import com.yz.jdd.network.ApiCallback;
import com.yz.jdd.network.RetrofitUtils;


import java.util.Map;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 项目名称：Maneki
 * 创建人：zx
 * 创建时间：2017/2/10-下午1:48
 */

public class H5Subscription {
//    public static Subscription h5Subscription(String url, JsonObject request, ApiCallback callback) {
//        return H5NetWorkHelper.getRequestInterface().h5SendPostMsg(url,request)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(callback);
//    }
    public static Subscription h5PostSubscription(Map<String,Object> headers,String url, JsonObject request, ApiCallback callback) {
        return H5NetWorkHelper.getRequestInterface().h5RequestPost(headers,url,request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(callback);
    }
    public static Subscription h5GetSubscription(Map<String,Object> headers,String url, Map<String,Object> request, ApiCallback callback) {
        return H5NetWorkHelper.getRequestInterface().h5RequestGet(headers,url,request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(callback);
    }
    public static Subscription h5LogoutSubscription(ApiCallback callback)
    {
        return H5NetWorkHelper.getRequestInterface().h5LogoutGet()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(callback);

    }

}

class H5NetWorkHelper extends RetrofitUtils {
    private static H5RequestInterface requestInterface;
    public static H5RequestInterface getRequestInterface() {
        if (requestInterface == null) {
            synchronized (H5NetWorkHelper.class) {
                if (requestInterface == null) {
                    requestInterface = getRetrofit().create(H5RequestInterface.class);
                }
            }

        }
        return requestInterface;
    }
}